package com.jinke.api.modules.ums.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jinke.api.modules.ums.mapper.UmsAdminLogMapper;
import com.jinke.api.modules.ums.model.UmsAdminLog;
import com.jinke.api.modules.ums.request.LogQueryRequest;
import com.jinke.api.modules.ums.service.UmsAdminLogService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author macro
 * @since 2023-07-13
 */
@Service
public class UmsAdminLogServiceImpl extends ServiceImpl<UmsAdminLogMapper, UmsAdminLog> implements UmsAdminLogService {
    @Override
    public Page<UmsAdminLog> list(LogQueryRequest request) {

        Page<UmsAdminLog> page = new Page<>(request.getPageNum(), request.getPageSize());
        QueryWrapper<UmsAdminLog> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .like(request.getUsername() != null, UmsAdminLog::getUsername, request.getUsername())
                .like(request.getUri() != null, UmsAdminLog::getUri, request.getUri())
                .like(request.getIp() != null, UmsAdminLog::getIp, request.getIp())
                .ge(request.getStartDate() != null, UmsAdminLog::getCreatedAt, request.getStartDate())
                .le(request.getEndDate() != null, UmsAdminLog::getCreatedAt, request.getEndDate())
                .orderByDesc(UmsAdminLog::getId);


        return page(page, wrapper);
    }
}
